package cc.vv.baselibrary.http;


import java.io.Serializable;
import java.util.HashMap;

import cc.vv.baselibrary.bean.base.BaseRequestObj;
import cc.vv.baselibrary.util.LKJsonUtil;
import cc.vv.lkbasecomponent.http.LKHttp;
import cc.vv.lkbasecomponent.http.lib.setting.Settings;
import cc.vv.lklibrary.log.LogOperate;


/**
 * 接口请求统一工具类
 * Created by 025 on 2018/7/12.
 */
public class BaseHttpRequest implements Serializable {

    /**
     * get请求
     *
     * @param path          请求地址
     * @param request       请求实体（BaseRequestObj）
     * @param responseClass 响应实体
     * @param isShowLoading loading圈是否显示
     */
    public static void getRequest(String path, BaseRequestObj request, Class responseClass, boolean isShowLoading) {
        try {
            String jsonString = LKJsonUtil.objConversionJsonString(request);
            HashMap<String, Object> stringObjectHashMap = LKJsonUtil.parseJsonToMap(jsonString);
            LKHttp.get(path, stringObjectHashMap, responseClass, new BaseHttpCallBack<>(), isShowLoading);
        } catch (Exception e) {
            LogOperate.e(e.getMessage(), e);
        }
    }

    /**
     * get请求
     *
     * @param path          请求地址
     * @param request       请求实体（BaseRequestObj）
     * @param responseClass 响应实体
     * @param isShowLoading loading圈是否显示
     * @param settings      请求类型设置，如Settings(MediaTypeWrap.MEDIA_TYPE_FORM)
     */
    public static void getRequest(String path, BaseRequestObj request, Class responseClass, boolean isShowLoading, Settings... settings) {
        try {
            String jsonString = LKJsonUtil.objConversionJsonString(request);
            HashMap<String, Object> stringObjectHashMap = LKJsonUtil.parseJsonToMap(jsonString);
            LKHttp.get(path, stringObjectHashMap, responseClass, new BaseHttpCallBack<>(), isShowLoading, settings);
        } catch (Exception e) {
            LogOperate.e(e.getMessage(), e);
        }
    }

    /**
     * get请求
     *
     * @param path          请求地址
     * @param request       请求实体（Object）
     * @param responseClass 响应实体
     * @param isShowLoading loading圈是否显示
     */
    public static void getRequest(String path, Object request, Class responseClass, boolean isShowLoading) {
        try {
            LKHttp.get(path, request, responseClass, new BaseHttpCallBack<>(), isShowLoading);
        } catch (Exception e) {
            LogOperate.e(e.getMessage(), e);
        }
    }

    /**
     * get请求
     *
     * @param path          请求地址
     * @param request       请求实体（Object）
     * @param responseClass 响应实体
     * @param isShowLoading loading圈是否显示
     * @param settings      请求类型设置，如Settings(MediaTypeWrap.MEDIA_TYPE_FORM)
     */
    public static void getRequest(String path, Object request, Class responseClass, boolean isShowLoading, Settings... settings) {
        try {
            LKHttp.get(path, request, responseClass, new BaseHttpCallBack<>(), isShowLoading, settings);
        } catch (Exception e) {
            LogOperate.e(e.getMessage(), e);
        }
    }


    /**
     * post请求
     *
     * @param path          请求地址
     * @param request       请求实体（BaseRequestObj）
     * @param responseClass 响应实体
     * @param isShowLoading loading圈是否显示
     */
    public static void postRequest(String path, BaseRequestObj request, Class responseClass, boolean isShowLoading) {
        try {
            String jsonString = LKJsonUtil.objConversionJsonString(request);
            HashMap<String, Object> stringObjectHashMap = LKJsonUtil.parseJsonToMap(jsonString);
            LKHttp.post(path, stringObjectHashMap, responseClass, new BaseHttpCallBack(), isShowLoading);
        } catch (Exception e) {
            LogOperate.e(e.getMessage(), e);
        }
    }

    /**
     * post请求
     *
     * @param path          请求地址
     * @param request       请求实体（BaseRequestObj）
     * @param responseClass 响应实体
     * @param isShowLoading loading圈是否显示
     * @param settings      请求类型设置，如Settings(MediaTypeWrap.MEDIA_TYPE_FORM)
     */
    public static void postRequest(String path, BaseRequestObj request, Class responseClass,
                                   boolean isShowLoading, Settings... settings) {
        try {
            String jsonString = LKJsonUtil.objConversionJsonString(request);
            HashMap<String, Object> stringObjectHashMap = LKJsonUtil.parseJsonToMap(jsonString);
            LKHttp.post(path, stringObjectHashMap, responseClass, new BaseHttpCallBack(), isShowLoading, settings);
        } catch (Exception e) {
            LogOperate.e(e.getMessage(), e);
        }
    }

    /**
     * post请求
     *
     * @param path          请求地址
     * @param request       请求实体（Object）
     * @param responseClass 响应实体
     * @param isShowLoading loading圈是否显示
     */
    public static void postRequest(String path, Object request, Class responseClass, boolean isShowLoading) {
        try {
            LKHttp.post(path, request, responseClass, new BaseHttpCallBack(), isShowLoading);
        } catch (Exception e) {
            LogOperate.e(e.getMessage(), e);
        }
    }

    /**
     * post请求
     *
     * @param path          请求地址
     * @param request       请求实体（Object）
     * @param responseClass 响应实体
     * @param isShowLoading loading圈是否显示
     * @param settings      请求类型设置，如Settings(MediaTypeWrap.MEDIA_TYPE_FORM)
     */
    public static void postRequest(String path, Object request, Class responseClass, boolean isShowLoading, Settings... settings) {
        try {
            LKHttp.post(path, request, responseClass, new BaseHttpCallBack(), isShowLoading, settings);
        } catch (Exception e) {
            LogOperate.e(e.getMessage(), e);
        }
    }

    /**
     * 文件请求
     *
     * @param path          请求地址
     * @param request       请求实体（Object）
     * @param responseClass 响应实体
     * @param isShowLoading loading圈是否显示
     */
    public static void postFileRequest(String path, BaseRequestObj request, Class responseClass, boolean isShowLoading) {
        try {
            LKHttp.upLoad(path, request, responseClass, new BaseHttpCallBack(), isShowLoading);
        } catch (Exception e) {
            LogOperate.e(e.getMessage(), e);
        }
    }


}
